Skip to content

Add kindergarten-garden#152

Merged
keiravillekode merged 1 commit intoexercism:mainfrom
keiravillekode:kindergarten-garden
Mar 6, 2026
Merged

Add kindergarten-garden#152
keiravillekode merged 1 commit intoexercism:mainfrom
keiravillekode:kindergarten-garden

Conversation

@keiravillekode
Copy link
Contributor

No description provided.


def plants (diagram : String) (student: String) : Vector Plant 4 :=
let letters := diagram.toList
let first := 2 * ((student.toList)[0]!.val.toNat - 65)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use student.front to access the first letter in a String. Since Lean is not lazy, .toList is O(n).

let second := first + 1
let third := (diagram.length + 1) / 2 + first
let fourth := third + 1
let firstPlant := lookup letters[first]!
Copy link
Contributor

@oxe-i oxe-i Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can access individual Chars using String.Pos.get. In the version we are using, if we cast String to String.Slice and get startPos with, e.g., letters := diagram.toSlice.startPos, then we can use (letters.nextn first).get! to get the letter at position first.

I found that the Lean version we are using is right in the middle of an API change to the String type. In the latest version there is no need to cast String to String.Slice, this is done implicitly.

@keiravillekode keiravillekode merged commit a29e182 into exercism:main Mar 6, 2026
4 checks passed
@keiravillekode keiravillekode deleted the kindergarten-garden branch March 6, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants